package br.com.hmm.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import br.com.hmm.entidade.ProLabore;

public class ContaSocioDAO {
	
	private Connection conn = null;	
	
	private static final String ASSOCIAR_CONTA = "INSERT INTO CONTA_SOCIO(CONTA_CON_ID, SOCIO_SOC_ID) VALUES(?, ?) ;";
	private static final String UPDATE_CONTA_SOCIO = "UPDATE CONTA_SOCIO SET COS_RENDA_MENSAL = ? , COS_DATA_PAGAMENTO = ? WHERE CONTA_CON_ID = ? AND SOCIO_SOC_ID = ? ;";
	
	
	public ContaSocioDAO(){
		
	}
	
	
	public boolean inserir(ProLabore contaSocio) throws Exception{
		PreparedStatement stmt = null;
		
		try {
			FabricaConexao.getInstancia();
			this.conn = FabricaConexao.conectar();
			stmt = this.conn.prepareStatement(ASSOCIAR_CONTA);
			stmt.setInt(1, contaSocio.getConta().getId());
			stmt.setInt(2, contaSocio.getSocio().getId());
			//stmt.setDouble(3, contaSocio.getValor());
			//stmt.setDate(4, new java.sql.Date(contaSocio.getDataPagamento().getTime()));
			if(stmt.executeUpdate() > 0){
				return true;
			}
		}catch (Exception e) {
			throw new Exception(e.getLocalizedMessage());
		}finally{
			DAOUtil.close(this.conn, stmt);
		}
		return false;
	}
	
	
	public boolean atualizar(ProLabore contaSocio) throws Exception{
		PreparedStatement stmt = null;
		try {
			FabricaConexao.getInstancia();
			this.conn = FabricaConexao.conectar();
			stmt = this.conn.prepareStatement(UPDATE_CONTA_SOCIO);
			stmt.setDouble(1, contaSocio.getValor());
			stmt.setDate(2, new java.sql.Date(contaSocio.getDataPagamento().getTime()));
			stmt.setInt(3, contaSocio.getConta().getId());
			stmt.setInt(4, contaSocio.getSocio().getId());
			if(stmt.executeUpdate() > 0){
				return true;
			}
		}catch (Exception e) {
			throw new Exception(e.getLocalizedMessage());
		}finally{
			DAOUtil.close(this.conn, stmt);
		}
		return false;
	}
	

	

}
